package com.yzk.train.member.controller;

import com.yzk.train.common.response.Result;
import com.yzk.train.member.request.MemberLoginReq;
import com.yzk.train.member.request.MemberRegisterReq;
import com.yzk.train.member.request.MemberSendCodeReq;
import com.yzk.train.member.response.MemberLoginResp;
import com.yzk.train.member.service.MemberService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/")
public class MemberController {

    @Resource
    private MemberService memberService;

    @PostMapping("/register")
    public Result<Long> register(@Valid @RequestBody MemberRegisterReq req) {
        return Result.ok(memberService.register(req));
    }

    @PostMapping("/send-code")
    public Result<Long> sendCode(@Valid @RequestBody MemberSendCodeReq req) {
        memberService.sendCode(req);
        return Result.okMessage("发送成功");
    }

    @PostMapping("/login")
    public Result<MemberLoginResp> sendCode(@Valid @RequestBody MemberLoginReq req) {
        return Result.ok(memberService.login(req));
    }

}
